package com.example.demo.netty.chat;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ChatClient {
    public static void main(String[] args) {
        EventLoopGroup boss = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(boss).channel(NioSocketChannel.class)
                    .handler(new ChatClientInit());
            Channel channel = bootstrap.connect("localhost", 8888).sync().channel();
            BufferedReader bw = new BufferedReader(new InputStreamReader(System.in));
            for (; ; ) {
                String line = bw.readLine();
                channel.writeAndFlush(line+"\r\n");
            }

        } catch (Exception e) {
            boss.shutdownGracefully();
        }
    }
}
